package com.qishanor.system.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.hutool.core.lang.tree.Tree;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.qishanor.framework.base.DictVO;
import com.qishanor.framework.util.R;
import com.qishanor.system.model.SysDept;
import com.qishanor.system.service.SysDeptService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @description: 部门管理
 * @author: 周振林
 * @date: 2022-04-12
 * @Copyright: 博客：http://www.zhouzhenlin.com - 沉淀、分享、成长、让自己和他人都有所收获
 **/

@RestController
@RequestMapping("/api/sys/dept")
public class SysDeptController {

    @Autowired
    private SysDeptService sysDeptService;


    @GetMapping("/tree")
    @SaCheckPermission("sys_dept_view")
    public R tree(String name){
        return R.ok(sysDeptService.tree(name));
    }

    @GetMapping("/{id}")
    public R getById(@PathVariable Integer id){
        return R.ok(sysDeptService.getById(id));
    }

    @PostMapping
    @SaCheckPermission("sys_dept_add")
    public R save(@RequestBody SysDept sysDept){
        return R.ok(sysDeptService.saveDept(sysDept));
    }

    @PutMapping
    @SaCheckPermission("sys_dept_edit")
    public R update(@RequestBody SysDept sysDept){
        return R.ok(sysDeptService.updateDept(sysDept));
    }

    @DeleteMapping("/{id}")
    @SaCheckPermission("sys_dept_del")
    public R deleteById(@PathVariable Integer id){
        return R.ok(sysDeptService.removeDeptById(id));
    }

}
